home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / face2ps.zip / FACE2PS.C next >
C/C++ Source or Header  |  1993-01-25  |  7KB  |  203 lines

  1. Here is a slightly updated version of the "printuface.c" program
  2. provided by faceserver's "send format" request.  It is called
  3. "face2ps.c", solely because I don't like the name "printuface" (well... and
  4. because it doesn't PRINT anything, it only converts).  This one doesn't
  5. care where interesting header lines are, as long as they start with the
  6. right keywords (case sensitive!!).  It is by no means bulletproof, but
  7. it should do a better job than the current program.
  8.  
  9. Please distribute freely.  Thanks for the faceserver.
  10.  
  11. -David
  12. ----------------------------------------------------------------------------
  13. /* Simple program to read in an 8-bit deep picture file from a Targa M8
  14.  * board and display it via PostScript.
  15.  *
  16.  * Copyright 1988,1989 Metron Computerware, Ltd. Oakland, CA 94602
  17.  * Unpublished work of Metron Computerware, Ltd.  All rights reserved.
  18.  *
  19.  * Small pictures have already been rotated from the original raster by the
  20.  * capture program to print in a proper orientation on the paper.
  21.  *
  22.  * Last revised 21 March 1989
  23.  *
  24.  * This program first outputs a postscript program to stdout.
  25.  * It then reads stdin or a file to get the hexified image.
  26.  * It sends this postscript stuff to stdout.
  27.  *
  28.  * Usage: face2ps [fn] [< hexpicturefile] > postscriptdevice
  29.  *        if any argument is supplied at all, the program expects to read
  30.  *        that as a uunet formatted file.  Otherwise it reads that format
  31.  *        from stdin.
  32.  *
  33.  * cc -o face2ps face2ps.c
  34.  *
  35.  * The pixels on a Targa board are not quite square.  In fact, they are
  36.  * off by the ratio 96:108, very nearly
  37.  *
  38.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  39.  *
  40.  * Now supports non-fixed uunet faceserver header format.  The order and
  41.  * number of lines in the header don't matter, but keywords are still case
  42.  * sensitive.  Header is terminated by a blank line.
  43.  *
  44.  * Updated 21 December 1990
  45.  *
  46.  * Copyright (c) 1990, David Reisner Consulting.  All rights reserved.
  47.  * Please distribute freely, but don't remove the copyright notices.
  48.  * Internet: synthesis!dar@ucsd.edu; Faceserver: synthesis.uucp/dar.
  49.  *
  50.  */
  51.  
  52. #include <stdio.h>
  53. #include <string.h>
  54. #define SERIAL
  55.  
  56. char scanline[256];                 /* Input for one scanline           */
  57. main(argc,argv)
  58.     int argc;
  59.     char **argv;
  60. {
  61.     int d,i,j,k,l,m;
  62.     char textout[256];
  63.     char header[128];               /* A line from the header, which may be..*/
  64.     char fname[128];                /* The first name behind the face   */
  65.     char lname[128];                /* The last name behind the face    */
  66.     char netaddr[128];              /* Net address, if any              */
  67.     char pixinfo[128];              /* width, height, depth of data     */
  68.     char imageinfo[128];            /* width, height, depth of image    */
  69.     unsigned char ch,*cp;
  70.     FILE *fp;
  71.     int pt = 18;                    /* pointsize for message            */
  72.  
  73.     k = 128;                        /* Normal image                     */
  74.     l = 108;
  75.  
  76.     if (argc > 1) {
  77.     fp = fopen(argv[1],"r");
  78.     if (fp == NULL) {
  79.         printf("Can't open %s for input\n",argv[1]);
  80.         exit (1);
  81.     }
  82.     }
  83.     else
  84.     fp = stdin;
  85.  
  86.  
  87.     /* Extract the "FirstName:", "LastName:", "E-Mail:", "PicData:", and
  88.        "Image:" info from the header (terminated by a blank line). */
  89.     while (strlen(fgets(header, 127,fp)) > 1)
  90.     {
  91.     if (strstr(header, "FirstName:") == header)
  92.         strncpy(fname,     header,127);
  93.     if (strstr(header, "LastName:")  == header)
  94.         strncpy(lname,     header,127);
  95.     if (strstr(header, "E-mail:")    == header)
  96.         strncpy(netaddr,   header,127);
  97.     if (strstr(header, "PicData:")   == header)
  98.         strncpy(pixinfo,   header,127);
  99.     if (strstr(header, "Image:")     == header)
  100.         strncpy(imageinfo, header,127);
  101.     }
  102.     sscanf(pixinfo,"%s %d %d %d",scanline,&l,&k,&d);
  103.     if (l == 108 || l == 96)
  104.     k = 128;
  105.     else {
  106.     printf("Bad picture width %d\n", l);
  107.     exit (1);
  108.     }
  109.  
  110.     d = 0;
  111.  
  112.     /* Simpleminded stupid construction and output of a postscript      */
  113.     /* program.  This IS NOT proper encapsulated PostScript format      */
  114.  
  115.     sprintf(textout,"/piktur %d %d mul string def\n",k,l);
  116.     write(1,textout,strlen(textout));
  117.  
  118.     sprintf(textout,"/main {\n/Helvetica findfont %d scalefont setfont\n",pt);
  119.     write(1,textout,strlen(textout));
  120.  
  121.     sprintf(textout,"currentscreen /p exch def\n");
  122.     write(1,textout,strlen(textout));
  123.     sprintf(textout,"pop pop 50 45 /p load setscreen\n");
  124.     write(1,textout,strlen(textout));
  125.  
  126.     /* This transfer function prevents pure white on 300 dpi laser printers */
  127.     sprintf(textout,
  128.     " { 1.05 mul 0.05 add dup .99 gt { pop .99 } if } settransfer\n");
  129.     write(1,textout,strlen(textout));
  130.  
  131.     sprintf(textout,"gsave\n72 72 translate 108 %d moveto\n",d+pt+2);
  132.     write(1,textout,strlen(textout));
  133.     sprintf(textout,"(%s) show\n",fname);
  134.     write(1,textout,strlen(textout));
  135.     sprintf(textout,"108 %d moveto\n",d);
  136.     write(1,textout,strlen(textout));
  137.     sprintf(textout,"(%s) show\n",lname);
  138.     write(1,textout,strlen(textout));
  139.  
  140.     sprintf(textout,"108 %d moveto\n",d-(pt+2));
  141.     write(1,textout,strlen(textout));
  142.     sprintf(textout,"(%s) show grestore\n",netaddr);
  143.     write(1,textout,strlen(textout));
  144.  
  145.     /* This line causes the hex image to be read into the string 'piktur'*/
  146.     sprintf(textout,"currentfile piktur readhexstring pop pop \n");
  147.     write(1,textout,strlen(textout));
  148.  
  149.     sprintf(textout,"72 -1100 translate\n0 0 moveto\n2.5 2.5 scale\n");
  150.     write(1,textout,strlen(textout));
  151.  
  152.     /*The factor 1.125 compensates for rectangular pixels in the Targa Board*/
  153.     if (l == 108)
  154.     sprintf(textout, "360 1.125 div 1.375 mul  360 1.375 mul scale\n");
  155.     else
  156.     sprintf(textout, "360           1.375 mul  360 1.375 mul scale\n");
  157.     write(1,textout,strlen(textout));
  158.  
  159.  
  160.     /* These lines setup the matrix and display a large copy of the picture */
  161.     sprintf(textout,"%d %d 8 ",l,k);
  162.     write(1,textout,strlen(textout));
  163.  
  164.     sprintf(textout,"[ 256 0 0 256 0 -256 ] \n");
  165.     write(1,textout,strlen(textout));
  166.     sprintf(textout,"{ piktur } image \n");
  167.     write(1,textout,strlen(textout));
  168.  
  169.  
  170.     sprintf(textout,"0.0 0.8 translate\n0.25 0.25 scale\n");
  171.     write(1,textout,strlen(textout));
  172.  
  173.     /* These lines setup the matrix and display a small copy of the picture */
  174.  
  175.     sprintf(textout,"%d %d 8 ",l,k);
  176.     write(1,textout,strlen(textout));
  177.     sprintf(textout,"[ 512 0 0 512 0 -256 ] \n");
  178.     write(1,textout,strlen(textout));
  179.  
  180.     sprintf(textout," { piktur } ");
  181.     write(1,textout,strlen(textout));
  182.  
  183.     sprintf(textout,"image showpage} def\n");
  184.     write(1,textout,strlen(textout));
  185.     sprintf(textout,"main\n");
  186.     write(1,textout,strlen(textout));
  187.  
  188.     /* The Hexified file has the ouput scanlines broken into 4 pieces,
  189.      * and each piece is twice as wide as the number of pixels, since
  190.      * each byte is converted to two hex digits.
  191.      * Thus each piece is not too wide, for screen readability.
  192.      */
  193.  
  194.     m = l + 1;         /* Hexified info plus newline */
  195.     for (i=0;i<k*4;i++) {
  196.         fgets(scanline,m,fp);
  197.         printf("%s",scanline);
  198.     }
  199.  
  200.     /* Terminate the PostScript with an EOF */
  201.     printf("\n\004");
  202. }
  203.